package com.qf.springmvc02.util;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;

import java.io.IOException;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author 钻五大人
 * @date 2022/5/5 9:36
 */

public class SalarySerializer implements ObjectSerializer {
    @Override
    public void write(JSONSerializer jsonSerializer, Object o, Object o1, Type type, int i) throws IOException {
        Double value = (Double) o;
        String str = BigDecimal.valueOf(value).setScale(2, RoundingMode.HALF_UP).toString();
        String text = str + "元";
        jsonSerializer.write(text);

    }
}
